package com.aube.interact;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;

import com.aube.interact.controller.AbstractController;
import com.aube.interact.controller.CardsController;
import com.aube.interact.controller.GoodsCardController;
import com.aube.interact.model.GoodsItem;
import com.aube.rvi.module.DLLayout;

import java.util.List;

/**
 * Created by huyaonan on 16/10/25.
 */
public class AubeInteractionLayout extends DLLayout implements AbstractController.IControllerCallback {

    private CardsController mCardsController;
    private GoodsCardController mGoodsController;

    private RelativeLayout mCardsLayout;
    private GoodsHotpotLayout mGoodsLayout;

    public AubeInteractionLayout(Context context) {
        this(context, null);
    }

    public AubeInteractionLayout(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public AubeInteractionLayout(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
    }

    @Override
    public void initViews() {
//        inflate(R.layout.aube_pulgin_controller, this, true);
        LayoutInflater inflater = LayoutInflater.from(context);
        inflater.inflate(R.layout.aube_pulgin_controller, this, true);

        mCardsLayout = (RelativeLayout) findViewById(R.id.card_root);
        mGoodsLayout = (GoodsHotpotLayout) findViewById(R.id.goods_root);
    }

    @Override
    public void fillData(String s) {
        mCardsController = new CardsController(context, mCardsLayout, s, this);
        mGoodsController = new GoodsCardController(context, mGoodsLayout, s, this);

        mCardsController.setupCards(0, true, true);
        mGoodsController.setupCards(0, true, true);
    }

    @Override
    public void onProgressChanged(long l) {
        if(mCardsController != null)
            mCardsController.locateCardByTime(l);
        if(mGoodsController != null)
            mGoodsController.locateCardByTime(l);
    }

    @Override
    public void onSeekComplete(long l) {
        mCardsController.setupCards(l, false, false);
        mGoodsController.setupCards(l, false, false);
        mCardsController.locateCardByTime(l);
        mGoodsController.locateCardByTime(l);
    }

    @Override
    public void onDestroy() {
        if(mGoodsController != null)
            mGoodsController.onDestroy();
        if(mCardsController != null)
            mCardsController.onDestroy();
        removeAllViews();
    }

    @Override
    public void onGoodsAdd(List<GoodsItem> data) {

    }

    @Override
    public void cancelGoods(String id) {

    }

    @Override
    public long getCurrentProgress() {
        return 0;
    }

    @Override
    public int[] getCartLocation() {
        return new int[0];
    }

    @Override
    public void hideFavorCart() {

    }
}
